/*
 * @Description:
 * @Autor: dongjunhua
 * @Date: 2021-01-28 10:12:07
 * @LastEditors: dongjunhua
 * @LastEditTime: 2022-04-14 10:19:41
 */

const { deepClone } = require('./utils');

const userList = [
  {
    id: '1',
    available: 'YES',
    versionDate: '2020-07-01 01:34:33.767',
    updator: '1',
    creator: '1',
    remark: '',
    name: 'Admin',
    code: 'admin',
    userType: 'ADMIN',
    mobilePhone: '15911111111',
    email: 'test@seasky.com',
    enabled: 'YES'
  },
  {
    id: '2',
    available: 'YES',
    versionDate: '2020-07-01 01:34:33.767',
    updator: '1',
    creator: '1',
    remark: '',
    name: 'Guest1',
    code: '0001',
    userType: 'ADMIN',
    mobilePhone: '15911111111',
    email: 'test@seasky.com',
    enabled: 'YES'
  },
  {
    id: '3',
    available: 'YES',
    versionDate: '2020-07-01 01:34:33.767',
    updator: '1',
    creator: '1',
    remark: '',
    name: 'Guest2',
    code: '0002',
    userType: 'ADMIN',
    mobilePhone: '15911111111',
    email: 'test@seasky.com',
    enabled: 'YES'
  }
];

const menuList = [
  {
    id: '5',
    available: 'YES',
    menuNo: '0001',
    name: '官方文档',
    icon: 'fas fa-file-alt',
    routingUrl: '',
    isNewWindow: 'NO',
    isSystem: 'YES',
    withUserId: 'NO',
    enabled: 'YES',
    authUser: ['1'],
    children: [
      {
        id: '6',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_005',
        name: 'Vue.js',
        icon: 'fab fa-vuejs',
        parentId: '1',
        routingUrl: 'frame/vue',
        redirectUrl: 'https://v3.cn.vuejs.org/',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      },
      {
        id: '8',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_008',
        name: 'Element Plus',
        icon: 'fab el-icon-platform-eleme',
        parentId: '1',
        routingUrl: 'frame/element-ui',
        redirectUrl: 'https://element-plus.gitee.io/#/zh-CN/',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      },
      {
        id: '7',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_008',
        name: 'Font Awesome',
        icon: 'fab fa-font-awesome-flag',
        parentId: '1',
        routingUrl: 'frame/font-awesome',
        redirectUrl: 'https://fa5.dashgame.com/#/',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      }
    ]
  },
  {
    id: '1',
    available: 'YES',
    versionDate: '2020-07-10 02:31:46.962',
    creator: '1',
    applicationId: '1',
    menuNo: '0000',
    name: '你好世界',
    icon: 'fas fa-globe-asia',
    parentId: '0',
    routingUrl: '',
    isNewWindow: 'NO',
    isSystem: 'YES',
    withUserId: 'NO',
    enabled: 'YES',
    authUser: ['1', '2'],
    children: [
      {
        id: '2',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_001',
        name: 'Hello A',
        icon: 'fas fa-cube',
        parentId: '1',
        routingUrl: 'hello/helloa',
        redirectUrl: '',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1', '2'],
        children: []
      },
      {
        id: '3',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_002',
        name: 'Hello B',
        icon: 'fas fa-feather-alt',
        parentId: '1',
        routingUrl: 'hello/hellob',
        redirectUrl: '',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      },
      {
        id: '4',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_003',
        name: 'Hello C',
        icon: 'fas fa-layer-group',
        parentId: '1',
        routingUrl: 'hello/helloc',
        redirectUrl: '',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      }
    ]
  },
  {
    id: '11',
    available: 'YES',
    versionDate: '2020-07-10 02:31:46.962',
    creator: '1',
    applicationId: '1',
    menuNo: '0000',
    name: '微应用',
    icon: 'fab fa-codepen',
    parentId: '0',
    routingUrl: '',
    isNewWindow: 'NO',
    isSystem: 'YES',
    withUserId: 'NO',
    enabled: 'YES',
    authUser: ['1', '2'],
    children: [
      {
        id: '12',
        available: 'YES',
        versionDate: '2020-07-10 05:53:01.597',
        updator: '1',
        creator: '1',
        applicationId: '1',
        menuNo: 'SBD_012',
        name: '微应用demo',
        icon: 'fab fa-codepen',
        parentId: '1',
        routingUrl: 'micro1',
        redirectUrl: '',
        urlParameter: '',
        isNewWindow: 'NO',
        isSystem: 'NO',
        withUserId: 'NO',
        enabled: 'YES',
        authUser: ['1'],
        children: []
      }
    ]
  }
  // {
  //   id: '6',
  //   available: 'YES',
  //   versionDate: '2020-07-10 05:53:01.597',
  //   updator: '1',
  //   creator: '1',
  //   applicationId: '1',
  //   menuNo: 'SBD_004',
  //   name: 'Hello D',
  //   icon: 'fas fa-fire-alt',
  //   parentId: '1',
  //   routingUrl: 'hello/hellod',
  //   redirectUrl: '',
  //   urlParameter: '',
  //   isNewWindow: 'NO',
  //   isSystem: 'NO',
  //   withUserId: 'NO',
  //   enabled: 'YES',
  //   authUser: ['1'],
  //   children: []
  // },
];

let currentUser = {};

function filterMenuNode(node, id) {
  if (node.children && node.children.length > 0) {
    node.children.forEach(c => filterMenuNode(c, id));
    node.children = node.children.filter(
      c =>
        (c.authUser && c.authUser.includes(id)) ||
        (c.children && c.children.length > 0)
    );
  }
}

function getMenuListByUser() {
  const { id } = currentUser;
  const menus = deepClone(menuList);
  filterMenuNode(menus[0], id);
  return menus;
}

module.exports = [
  // login
  {
    url: '/account/pc/v1/login',
    type: 'post',
    response: () => {
      return {
        data: [
          {
            id: '1',
            available: 'YES',
            versionDate: '2020-07-08 02:30:50.390',
            updator: '1',
            username: 'admin',
            enabled: 'YES',
            isInitial: 'NO',
            users: userList,
            token: 'd79ba79c-0561-43ed-afa4-d94a9ef2b5ff'
          }
        ],
        code: '00000',
        description: '成功',
        currentTime: '1594465972765',
        rid: 'pyAn4K2g'
      };
    }
  },
  // setCurrent
  {
    url: '/user/pc/v1/setCurrent',
    type: 'post',
    response: config => {
      const { id } = config.body;
      currentUser = userList.find(u => u.id === id);
      return {
        code: '00000',
        currentTime: '1594466609898',
        description: '成功',
        rid: '79HgNrDI'
      };
    }
  },
  // getCurrent
  {
    url: '/user/pc/v1/getCurrent',
    type: 'post',
    response: () => {
      return {
        data: [
          {
            ...currentUser,
            menuList: getMenuListByUser(),
            functionList: []
          }
        ],
        code: '00000',
        description: '成功',
        currentTime: '1594466793502',
        rid: 'YBi5A0sJ'
      };
    }
  },
  // modifyPassword
  {
    url: '/account/pc/v1/modifyPassword',
    type: 'post',
    response: () => {
      return {
        code: '00000',
        description: '成功',
        currentTime: '1594466793502',
        rid: 'YBi5A0sJ'
      };
    }
  }
];
